﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class Cart_Goods_UpdateController : UserController
    {
        public IArticle_goodsService _article_goods { get; set; }
        public IApp_cart_keysService _app_cart_keys { get; set; }
        public IArticleService _article { get; set; }
        public IUser_groupsService _user_groups { get; set; }
        // GET: api/Cart_Goods_Add
        [Authorize]
        [HttpGet]
        public IActionResult Get(int article_id,int goods_id,int quantity)
        {
            var user = GetUserInfo();
            if (user == null)
            {
                return Ok(new { status = 0, msg = "请先登录！" });
            }
            if (article_id <= 0)
            {
                return Ok(new { status = 0, msg = "您提交的商品参数有误！" });
            }
            if (quantity == 0)
            {
                return Ok(new { status = 0, msg = "购买数量不能小于1！" });
            }
            ShopCart.AppCartHelper shopcart = new ShopCart.AppCartHelper(_app_cart_keys, _article, _user_groups, _article_goods);
            App_cart_keys model = shopcart.Update(article_id, goods_id, quantity,user.id);
            if (model != null)
            {
                return Ok(new { status = 1, msg = "商品数量修改成功！", article_id = model.article_id, goods_id = model.goods_id, quantity = model.quantity });
            }
            return Ok(new { status = 0, msg = "请检查操作是否有误！" });
        }
    }
}